//
//  ValidationChecker.m
//  HuaYun
//
//  Created by enghou on 2018/12/8.
//  Copyright © 2018 xyxorigation. All rights reserved.
//

#import "ValidationChecker.h"

@implementation ValidationChecker

+(BOOL)valid{
    NSString *path = [[NSBundle mainBundle]pathForResource:@"Individual" ofType:@"cer"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    if (data) {
        SecCertificateRef cert = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)data);
        SecPolicyRef policy = SecPolicyCreateBasicX509();
        SecTrustRef trust;
        OSStatus error = SecTrustCreateWithCertificates((__bridge CFArrayRef)@[(__bridge id)cert], policy, &trust);
        SecTrustResultType trustResult = -1;
        error = SecTrustEvaluate(trust, &trustResult);
        CFRelease(trust);
        CFRelease(policy);
        CFRelease(cert);
        if (trustResult == kSecTrustResultUnspecified || trustResult == kSecTrustResultProceed) {
            return YES;
        } else {
            return NO;
        }
    }
    return NO;
}

@end
